package com.yupi.springbootinit.statemachine.rule;

import lombok.Data;

/**
 * 规则验证结果
 */
@Data
public class RuleValidationResult {
    
    /**
     * 验证是否通过
     */
    private boolean valid;
    
    /**
     * 错误消息
     */
    private String errorMessage;
    
    /**
     * 错误代码
     */
    private String errorCode;
    
    /**
     * 附加数据
     */
    private Object data;
    
    private RuleValidationResult(boolean valid, String errorMessage, String errorCode, Object data) {
        this.valid = valid;
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
        this.data = data;
    }
    
    /**
     * 创建成功结果
     */
    public static RuleValidationResult success() {
        return new RuleValidationResult(true, null, null, null);
    }
    
    /**
     * 创建成功结果（带数据）
     */
    public static RuleValidationResult success(Object data) {
        return new RuleValidationResult(true, null, null, data);
    }
    
    /**
     * 创建失败结果
     */
    public static RuleValidationResult failure(String errorMessage) {
        return new RuleValidationResult(false, errorMessage, null, null);
    }
    
    /**
     * 创建失败结果（带错误代码）
     */
    public static RuleValidationResult failure(String errorMessage, String errorCode) {
        return new RuleValidationResult(false, errorMessage, errorCode, null);
    }
    
    /**
     * 创建失败结果（完整参数）
     */
    public static RuleValidationResult failure(String errorMessage, String errorCode, Object data) {
        return new RuleValidationResult(false, errorMessage, errorCode, data);
    }
}